Foreign Function Interface (FFI) implementation#46905
Closed
bengl wants to merge 6 commits into
Closed
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's a first pass at implementing a foreign function interface (FFI). It's roughly based on my attempt at building an FFI library in userland. That implementation uses
dyncall, which doesn't support all the platforms that Node.js does, so I've usedlibffiinstead.As an example, this works on my PR branch.
$ cat test.c int test_add(int a, int b) { return a + b; } $ clang -shared -undefined dynamic_lookup -o libtest.so test.c $ ./node -p "require('node:ffi').getNativeFunction('./libtest.so', 'test_add', 'int', ['int', 'int'])(7, 5)" 12Here is the new doc page for this.
Limitations
Open Questions
libffibe updated/maintained?char *arguments?